const Oracledb = require('oracledb');
const logger = require('./logger')
const Oracle = {
  connect: (connectInfo) => {
    return new Promise(function (resolve, reject) {
      Oracledb.getConnection(connectInfo, function (err, conn) {
        if (err) {
          logger.error("Orcale connect fail", err.message)
          console.log(err.message);
          reject(err)
        }
        console.log("oracleDB连接成功");
        resolve(conn);
      });
    });
  },
  close: conn => {
    return new Promise(function (resolve, reject) {
      conn.close(err => {
        if (err) {
          logger.error("Orcale close fail", err.message)
          console.error(err.message);
          reject(err)
        }
        console.log("关闭连接");
        resolve();
      });
    })
  }
}

module.exports = {
  Oracle
};